<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>仓库管理</title>
    <link rel="stylesheet" href="/js/elementui/index.css">
    <style>
        .is-selected {
            color: #1989FA;
        }
        .el-dropdown-link {
            cursor: pointer;
            color: #409EFF;
        }
        .el-icon-arrow-down {
            font-size: 12px;
        }
    </style>
</head>
<body>
<div id="app">
    <div class="demo-input-size">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="仓库名称">
                <el-input v-model="formInline.name" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="创建时间" >
                <el-input v-model="formInline.dateTime" placeholder=""></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">搜索</el-button>
            </el-form-item>
        </el-form>
    </div>
    <br>

    <el-button type="primary" @click="dialogFormVisible = true">新增仓库</el-button>
    <!--数据表格-->
    <el-table
            ref="wareTable"
            :data="tableData"
            style="width: 100%">
        <el-table-column label="仓库id">
            <template slot-scope="scope">
                <span >{{ scope.row.id }}</span>
            </template>
        </el-table-column>
        <el-table-column label="仓库编号">
            <template slot-scope="scope">
                <span >{{ scope.row.wareNo }}</span>
            </template>
        </el-table-column>
        <el-table-column label="仓库名称">
            <template slot-scope="scope">
                <span >{{ scope.row.wareName }}</span>
            </template>
        </el-table-column>
        <el-table-column label="负责人">
            <template slot-scope="scope">
                <span >{{ scope.row.person}}</span>
            </template>
        </el-table-column>
        <el-table-column label="联系电话">
            <template slot-scope="scope">
                <span >{{ scope.row.telephone }}</span>
            </template>
        </el-table-column>
        <el-table-column label="货区数目">
            <template slot-scope="scope">
                <span >{{ scope.row.cargoNum }}</span>
            </template>
        </el-table-column>
        <el-table-column label="货架数目">
            <template slot-scope="scope">
                <span >{{ scope.row.shelvesNum }}</span>
            </template>
        </el-table-column>
        <el-table-column label="货位数目">
            <template slot-scope="scope">
                <span >{{ scope.row.totalNum }}</span>
            </template>
        </el-table-column>
        <el-table-column label="空置货位">
            <template slot-scope="scope">
                <span >{{ scope.row.emptySpace }}</span>
            </template>
        </el-table-column>
        <el-table-column label="仓库描述">
            <template slot-scope="scope">
                <span >{{ scope.row.details }}</span>
            </template>
        </el-table-column>
        <el-table-column label="创建时间">
            <template slot-scope="scope">
                <span >{{ scope.row.deteTime }}</span>
            </template>
        </el-table-column>
        <el-table-column label="状态">
            < <template slot-scope="scope">
                <el-button type="success" icon="el-icon-check" v-if="scope.row.status==0" @click="confirmStorage(scope.$index,scope.row)"></el-button>
                <el-button type="info" icon="el-icon-check" disabled  v-if="scope.row.status==1" ></el-button>
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index,scope.row)">删除</el-button>
            </template>
        </el-table-column>

    </el-table>
    <!--分页-->
    <nav style="text-align: center">  <!-- 分页居中放置-->
        <el-pagination
                background
                layout="prev, pager, next"
                @current-change="loadPage"
                :total="total"
                :current-page="current"
                :page-size="pageSize">
        </el-pagination>
    </nav>

    <!--保存添加仓库的对话框-->
    <el-dialog title="添加仓库" :visible.sync="dialogFormVisible" @close="closeMyDialog">
        <el-form :model="ware">
            <el-form-item label="仓库编号" :label-width="formLabelWidth">
                <el-input v-model="ware.wareNo" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="ware">
            <el-form-item label="仓库名称" :label-width="formLabelWidth">
                <el-input v-model="ware.wareName" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="ware">
            <el-form-item label="负责人" :label-width="formLabelWidth">
                <el-input v-model="ware.person" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="ware">
            <el-form-item label="联系电话" :label-width="formLabelWidth">
                <el-input v-model="ware.telephone" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="ware">
            <el-form-item label="货区数目" :label-width="formLabelWidth">
                <el-input v-model="ware.cargoNum" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="ware">
            <el-form-item label="货架数目" :label-width="formLabelWidth">
                <el-input v-model="ware.shelvesNum" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="ware">
            <el-form-item label="货位数目" :label-width="formLabelWidth">
                <el-input v-model="ware.totalNum" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="ware">
            <el-form-item label="空置货位" :label-width="formLabelWidth">
                <el-input v-model="ware.emptySpace" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <el-form :model="ware">
            <el-form-item label="仓库描述" :label-width="formLabelWidth">
                <el-input v-model="ware.details" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <!--<el-form :model="ware">
            <el-form-item label="创建时间" :label-width="formLabelWidth">
                <el-input v-model="ware.deteTime" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>-->
        <el-form :model="ware">
            <el-form-item label="仓库状态" :label-width="formLabelWidth">
                <el-input v-model="ware.status" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>



        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="saveWare()">确 定</el-button>
        </div>
    </el-dialog>
</div>

</body>

<script src="/js/vue/vue.js"></script>
<script src="/js/axios/axios.min.js"></script>
<script src="/js/qs/qs.min.js"></script>
<!-- 引入组件库 -->
<script src="/js/elementui/index.js"></script>
<script>
    new Vue({
            el:"#app",
            data(){
                return {
                    status:'',
                    tableData: null,//表格数据
                    total:0,//总条数
                    current:1,//当前页数
                    pageSize:10, //每页条数
                    dialogFormVisible: false,//控制对话框的显示

                    ware:{
                        id:'',
                        wareNo:'',
                        wareName:'',
                        person:'',
                        telephone:'',
                        cargoNum:'',
                        details:'',
                        /*deteTime:'',*/
                        status:'',
                        address:'',
                        place:'',
                        /*companyId:'',*/
                        emptySpace:'',
                        shelvesNum:'',
                        totalNum:''
                    },
                    formInline: { //模糊查询的数据
                        name: '',
                        dateTime: ''
                    },
                    formLabelWidth:"120px" //表单标签的宽度
                }
            },
            methods:{

                /*状态栏的方法*/
                handleCommand(val){
                    this.status = this.status === 0 ?1:0;
                },

                /*模糊查询*/
                onSubmit(){
                    this.loadPage(1);
                    // axios.get("/ware/"+current)
                    //     .then(value => {
                    //         this.gridData=value.data.data;
                    //         this.dialogTableVisible=true;
                    //     })
                },

                loadPage(current){  //表格显示的方法
                    this.name=this.formInline.name;
                    this.dateTime=this.formInline.dateTime;
                    this.current=current;
                    // axios.get("/ware/"+current)
                    axios.get("/ware?current="+this.current+"&name="+this.name+"&dateTime="+this.dateTime)
                            .then(value => {
                            console.log(value)
                            if (value.data.code=1){
                                this.tableData=value.data.data.records;
                                this.total=value.data.data.total;
                                this.current=value.data.data.current;
                                this.pageSize=value.data.data.pageSize;
                            }
                        });
                },
                //显示修改用户的对话框
                handleEdit(index, row) {
                    //使用JSON.parse和JSON.stringify可以将数据以JSON形式赋给当前对象
                    this.ware=JSON.parse(JSON.stringify(row));
                    this.dialogFormVisible=true;
                },
                handleDelete(index, row) {
                    console.log(index, row);
                    this.deleteWare(row.id);
                },

                saveWare(){
                    if(this.ware.id==''){
                        axios.post("/ware",this.ware).then(value => { //JSON上传数据
                            if(value.data.code == 1){
                                this.loadPage(this.current);
                                this.$message(value.data.msg);
                            }
                        });
                    }else{
                        axios.put("/ware",this.ware).then(value => {
                            if(value.data.code==1){
                                this.loadPage(this.current)
                                this.$message(value.data.msg);
                            }
                        });
                    }
                    this.dialogFormVisible=false;
                },
                closeMyDialog(){
                    this.ware={   //关闭对话框时更改product属性
                        id:'',
                        wareNo:'',
                        wareName:'',
                        person:'',
                        telephone:'',
                        cargoNum:'',
                        details:'',
                        /*deteTime:'',*/
                        status:'',
                        address:'',
                        place:'',
                        /*companyId:'',*/
                        emptySpace:'',
                        shelvesNum:'',
                        totalNum: ''
                    }
                },
                deleteWare(id){
                    this.$confirm('此操作将永久删除该用户, 是否继续?', '提示',"/ware/{id}", {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(()=>{
                        axios.delete("/ware/"+id).then(value => {
                            console.log(id);
                            if (value.data.code == 1) {
                                this.loadPage(1);
                            }
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        });
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                }
            },

            mounted(){
                /*axios.get("/fatherFunctions").then(value => {
                    if (value.data.code==1){
                        this.fatherFunctionsData=value.data.data;
                    }
                })*/
                this.loadPage(1);
            }
        }

    )
</script>
</html>